package com.weihe.toolkit.csv;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import com.Ostermiller.util.ExcelCSVParser;
import com.Ostermiller.util.LabeledCSVParser;

/** 
 * 常用加密算法工具类 
 * @author cq 
 */  
public class CsvToolkit {
	public static String[][] read(String filePath) throws FileNotFoundException, IOException
    {
        return read(new FileInputStream(filePath));
    }
    
    public static String[][] read(InputStream in) throws IOException
    {
        LabeledCSVParser csvParser = new LabeledCSVParser(new ExcelCSVParser(in));
        String[][] arr = csvParser.getAllValues();
        csvParser.close();
        return arr;
    }
    
    public static List<ArrayList<String>> read2(String filePath) throws IOException
    {
        return read2(new FileInputStream(filePath));
    }
    
    public static List<ArrayList<String>> read2(InputStream in) throws IOException
    {
        ArrayList<ArrayList<String>> outterLst = new ArrayList<ArrayList<String>>();
        String[][] outerArr = read(in);
        
        ArrayList<String> innerLst = null;
        for(String[] innerArr : outerArr)
        {
            innerLst = new ArrayList<String>();
            for(String s : innerArr)
            {
                innerLst.add(s);
            }
            outterLst.add(innerLst);
        }
        return outterLst;
    }
}  